import Vue from "vue";
import {Dialog, Notify} from "vant";

const that = Vue.prototype//获取this
/**
 * 弹窗盒子
 * @param msg 提示信息
 * @param type 弹窗类型，默认warning
 */
export default function massageBox(msg, type = "warning") {
    return new Promise((resolve, reject) => {
        that.$confirm(msg, '系统提示', {
            confirmButtonText: '确定', cancelButtonText: '取消', type
        }).then(r => resolve(r)).catch(e => reject(e))
    })
}

/**
 * 通知-成功
 * @param message
 */
export function notifySuccess(message = "操作成功") {
    that.$notify({
        title: '成功', message, type: 'success'
    });
}

/**
 * 通知-失败
 * @param vm
 * @param message
 */
export function notifyError(message = "操作失败") {
    that.$notify({
        title: '失败', message, type: 'error'
    });
}

/**
 * 加载动画
 * @returns {ElLoadingComponent}
 */
export function loading(text = "文件上传中...") {
    return that.$loading({
        lock: true, text, spinner: "el-icon-loading", background: "rgba(0, 0, 0, 0.7)",
    });

}

/**
 * 弹窗-成功
 * @param msg
 */
export function meassageSuccess(msg) {
    that.$message.success(msg)
}

/**
 * 弹窗-失败
 * @param msg
 */
export function meassageError(msg) {
    that.$message.error(msg)
}

/**
 * 弹窗-警告
 * @param msg
 */
export function meassageWarning(msg) {
    that.$message.warning(msg)
}

/**
 * 弹窗-信息
 * @param msg
 */
export function meassageInfo(msg) {
    that.$message.info(msg)
}

/**
 * 消息确认弹窗
 * @param message
 * @returns {Promise<DialogAction>}
 * @constructor
 */
export function DialogMessageVerify(message = "消息确认提示") {
    return Dialog.confirm({
        title: '系统提示',
        message,
    })
}

/**
 * 成功提示
 * @returns {VanNotify}
 */
export function vantNotifySuccess(message) {
    return Notify({type: "success", message})
}

/**
 * 失败
 * @param message
 * @returns {VanNotify}
 */
export function vantNotifyDanger(message) {
    return Notify({type: "danger", message})
}